package team.seekers.hula.island.islandUser.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.island.islandUser.entity.dto.IslandUserBatchBindDTO;
import team.seekers.hula.island.islandUser.entity.dto.IslandUserBindDTO;
import team.seekers.hula.island.islandUser.entity.dto.IslandUserManagePageDTO;
import team.seekers.hula.island.islandUser.entity.dto.IslandUserUpdateDTO;
import team.seekers.hula.island.islandUser.entity.vo.IslandUserManagePageVO;
import team.seekers.hula.island.islandUser.service.IslandUserManageService;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * @author ekin
 * @Description GOOD
 * @mood happy
 */
@Controller
@ApiResponseBody
@RequestMapping("/manage/island/user")
public class IslandUserManageController {

    @Resource
    private IslandUserManageService islandUserManageService;

    /**
     *
     * 浪屿用户管理
     */
    @GetMapping("/page")
    public PageResult<IslandUserManagePageVO> pageUser(IslandUserManagePageDTO islandUserManagePageDTO) {
        if(islandUserManagePageDTO.getNotIn() == 1){
            return islandUserManageService.pageNotIn(islandUserManagePageDTO);
        }else{
            return islandUserManageService.pageUser(islandUserManagePageDTO);
        }
    }

    @GetMapping("/role/update")
    public void updateRole(IslandUserUpdateDTO islandUserUpdateDTO) {
        islandUserManageService.updateRole(islandUserUpdateDTO);
    }

    /**
     * 为当前选中的所有人绑定所有浪屿
     */
    @PostMapping("/batch-bind")
    public void batchBind(@RequestBody IslandUserBatchBindDTO islandUserBatchBindDTO){
        islandUserManageService.batchBind(islandUserBatchBindDTO);
    }


    /**
     * 浪屿用户绑定
     */
    @PostMapping("/bind")
    public void bind(@RequestBody IslandUserBindDTO islandUserBindDTO){
        ArrayList<String> userIds = new ArrayList<>();
        userIds.add(islandUserBindDTO.getUserId());
        ArrayList<String> islandIds = new ArrayList<>();
        islandIds.add(islandUserBindDTO.getIslandId());
        IslandUserBatchBindDTO islandUserBatchBindDTO = IslandUserBatchBindDTO.builder().islandIds(islandIds).userIds(userIds).role(islandUserBindDTO.getRole()).build();
        islandUserManageService.batchBind(islandUserBatchBindDTO);
    }

    /**
     *
     * 浪屿用户解绑
     */
    @GetMapping("/unbind")
    public void unbind(@RequestParam String userId,
                       @RequestParam String islandId) {
        islandUserManageService.unbind(userId,islandId);
    }

}
